//
//  InternalContactView.swift
//  willdo
//
//  Created by zz on 4/4/18.
//  Copyright © 2018 will do. All rights reserved.
//

import UIKit

class InternalMemberView: UIView {

    var imgView = UIImageView()
    var nameLabel = UILabel()
    var taskLabel = UILabel()
    
    var telImg = UIImageView()
    var telLabel = UILabel()
    var emailImg = UIImageView()
    var emailLabel = UILabel()
    var belongImg = UIImageView()
    var belongLabel = UILabel()
    var positionImg = UIImageView()
    var positionLabe = UILabel()
    var noteImg = UIImageView()
    var noteLabel = UILabel()
    
    var createTaskBtn = UIButton()
    
    var model:InternalMemberModel!
    init(frame:CGRect, model:InternalMemberModel){
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        self.model = model
        setupAvatar()
        setupInfo()
        
//        addSubview(createTaskBtn)
//        createTaskBtn.setTitle("创建任务", for: .normal)
//        createTaskBtn.setTitleColor(UIColor.black, for: .normal)
//        createTaskBtn.layer.borderWidth = 1
//        createTaskBtn.snp.makeConstraints { (make) in
//            make.centerX.equalToSuperview()
//            make.width.equalToSuperview().offset(-40)
//            make.height.equalTo(40)
//            make.bottom.equalToSuperview().offset(-44)
//        }
        
    }
    
    private func setupAvatar(){
        addSubview(imgView)
        imgView.image = UIImage(named: "head portrait")
        imgView.snp.makeConstraints { (make) in
            make.top.equalTo(73)
            make.centerX.equalToSuperview()
            make.height.width.equalTo(78)
        }
        addSubview(nameLabel)
        nameLabel.text = model.name
        nameLabel.font = UIFont.init(name: "PingFang SC", size: 20)
        nameLabel.textColor = UIColor(hexString: "#040000")
        nameLabel.snp.makeConstraints { (make) in
            make.top.equalTo(imgView.snp.bottom).offset(25)
            make.centerX.equalTo(imgView)
        }
        addSubview(taskLabel)
        taskLabel.text = model.task
        taskLabel.font = UIFont.init(name: "PingFang SC", size: 12)
        taskLabel.textColor = UIColor(hexString: "#496069")
        taskLabel.snp.makeConstraints { (make) in
            make.top.equalTo(nameLabel.snp.bottom).offset(17)
            make.centerX.equalTo(nameLabel)
        }
    }
    
    private func setupInfo(){
        let phoneView = getCell(img: telImg, label: telLabel)
        telImg.image = UIImage(named: "contact_picture")
        telLabel.text = model.tel
        phoneView.snp.makeConstraints { (make) in
            make.top.equalTo(taskLabel.snp.bottom).offset(38)
            make.height.equalTo(52)
            make.left.right.equalToSuperview()
        }
        let sepLine0 = UIView(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
        addSubview(sepLine0)
        sepLine0.backgroundColor = BACKGROUND_GRAY
        sepLine0.snp.makeConstraints { (make) in
            make.width.left.equalToSuperview()
            make.top.equalTo(phoneView.snp.bottom)
            make.height.equalTo(1)
        }
        
        let emailView = getCell(img: emailImg, label: emailLabel)
        emailImg.image = UIImage(named: "email_picture")
        emailLabel.text = model.email
        emailView.snp.makeConstraints { (make) in
            make.top.equalTo(sepLine0.snp.bottom)
            make.left.right.height.equalTo(phoneView)
        }
        let sepLine1 = UIView(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
        addSubview(sepLine1)
        sepLine1.backgroundColor = BACKGROUND_GRAY
        sepLine1.snp.makeConstraints { (make) in
            make.width.left.equalToSuperview()
            make.top.equalTo(emailView.snp.bottom)
            make.height.equalTo(1)
        }

        let belongView = getCell(img: belongImg, label: belongLabel)
        belongImg.image = UIImage(named: "department_picture")
        belongLabel.text = model.belong
        belongView.snp.makeConstraints { (make) in
            make.top.equalTo(sepLine1.snp.bottom)
            make.left.right.height.equalTo(emailView)
        }
        let sepLine2 = UIView(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
        addSubview(sepLine2)
        sepLine2.backgroundColor = BACKGROUND_GRAY
        sepLine2.snp.makeConstraints { (make) in
            make.width.left.equalToSuperview()
            make.top.equalTo(belongView.snp.bottom)
            make.height.equalTo(1)
        }

        let positionView = getCell(img: positionImg, label: positionLabe)
        positionImg.image = UIImage(named: "work_picture")
        positionLabe.text = model.position
        positionView.snp.makeConstraints { (make) in
            make.top.equalTo(sepLine2.snp.bottom)
            make.left.right.height.equalTo(belongView)
        }
        let sepLine3 = UIView(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
        addSubview(sepLine3)
        sepLine3.backgroundColor = BACKGROUND_GRAY
        sepLine3.snp.makeConstraints { (make) in
            make.width.left.equalToSuperview()
            make.top.equalTo(positionView.snp.bottom)
            make.height.equalTo(1)
        }
        
        let noteView = getCell(img: noteImg, label: noteLabel)
        noteImg.image = UIImage(named: "remark_picture")
        noteLabel.text = model.note
        noteView.snp.makeConstraints { (make) in
            make.top.equalTo(sepLine3.snp.bottom)
            make.left.right.equalTo(positionView)
            make.bottom.equalTo(noteLabel.snp.bottom)
        }
    }
    
    private func getCell(img:UIView, label:UILabel) -> UIView{
        let cellView = UIView()
        addSubview(cellView)
        cellView.backgroundColor = UIColor.white
        cellView.addSubview(img)
        cellView.addSubview(label)
        img.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(17)
            make.left.equalToSuperview().offset(27)
            make.height.width.equalTo(18)
        }
        label.sizeToFit()
        label.font = UIFont(name: "PingFang SC", size: 15)
        label.textColor = UIColor(hexString: "#496069")
        label.numberOfLines = 0
        label.snp.makeConstraints { (make) in
            make.top.equalTo(img)
            make.left.equalTo(img.snp.right).offset(17)
        }
        return cellView
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}